package o;

import android.content.Context;
import java.io.File;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class ere extends up {
    private e ˊ;
    private final int ˎ;

    static class d implements e {
        private final String ˋ;
        private final File ˎ;

        public d(Context context, String str) {
            this.ˎ = context.getCacheDir();
            this.ˋ = str;
        }

        public File ˋ() {
            if (this.ˎ == null) {
                return null;
            }
            if (this.ˋ != null) {
                return new File(this.ˎ, this.ˋ);
            }
            return this.ˎ;
        }
    }

    public ere(Context context, int i) {
        this(context, "image_manager_disk_cache", i);
    }

    public ere(Context context, String str, int i) {
        super(new d(context, str), (long) i);
        this.ˊ = new d(context, str);
        this.ˎ = i;
    }

    public static File ˋ(String str) {
        if (dof.ॱ(str)) {
            Logger.ˋ("CacheFactory", "key is null");
            return null;
        }
        String ˊ = eri.ˊ().ˊ(str);
        if (!dof.ॱ(ˊ)) {
            return new File(ˊ);
        }
        Logger.ˋ("CacheFactory", "get cache path is null, iconToken : " + str);
        return null;
    }

    public static String ˏ(String str) {
        String str2 = "";
        try {
            MessageDigest instance = MessageDigest.getInstance("md5");
            instance.update(str.getBytes("UTF-8"));
            byte[] digest = instance.digest();
            StringBuilder stringBuilder = new StringBuilder();
            for (byte b : digest) {
                String toHexString = Integer.toHexString(b & 255);
                if (1 == toHexString.length()) {
                    stringBuilder.append("0");
                }
                stringBuilder.append(toHexString);
            }
            str2 = stringBuilder.toString();
        } catch (NoSuchAlgorithmException e) {
            Logger.ˋ("CacheFactory", "getCacheFileKey NoSuchAlgorithmException iconUrl : " + str);
        } catch (IOException e2) {
            Logger.ˋ("CacheFactory", "getCacheFileKey IOException iconUrl : " + str);
        }
        return str2;
    }

    public uj ॱ() {
        File ˋ = this.ˊ.ˋ();
        if (ˋ == null) {
            return null;
        }
        if (ˋ.mkdirs() || (ˋ.exists() && ˋ.isDirectory())) {
            return erc.ˋ(ˋ, this.ˎ);
        }
        return null;
    }
}
